import cv2 as cv
import numpy as np

if __name__ == "__main__":
    file = "../res/opencv_腐蚀erode.jpg"
    img = cv.imread(file)
    cv.imshow("img", img)

    # 腐蚀
    kernel = np.ones((3, 3), np.uint8)
    erode_img = cv.erode(img, kernel, iterations=1)
    cv.imshow("erode_img", erode_img)

    # 二进化腐蚀
    # ret, otsu_img = cv.threshold(img, 0, 255, cv.THRESH_BINARY)
    ret, otsu_img = cv.threshold(img, 80, 255, cv.THRESH_BINARY_INV)
    erode_otsu_img = cv.erode(otsu_img, kernel, iterations=1)
    cv.imshow("erode_otsu_img", erode_otsu_img)

    cv.waitKey(0)
    cv.destroyAllWindows()
